home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT1-5 / FACTR.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  3.8 KB  |  89 lines

  1. .nolistmacro
  2. Page 60,132
  3. ;
  4. ;                        Program   FACTR
  5. ;                        ═══════════════
  6. ;                           Chapter 2
  7. ;
  8. ;                    Voronezh, 26 November  91
  9. ;                    ─────────────────────────
  10. ;          This  is  a  sample of an assembler program which
  11. ;          calculates the function called  n-factorial.   It
  12. ;          shows commands for organizing cycles and for data
  13. ;          examination.  To run the program enter the number
  14. ;          after  the  cursor  and then the separator symbol
  15. ;          (for example the factorial symbol "!").  To  exit
  16. ;          the program press the ENTER or ESC key instead of
  17. ;          the number.  You may meet commands  that  you  do
  18. ;          not   fully   uderstand   even   if  you  are  an
  19. ;          experienced user.  Don't worry about  them.   All
  20. ;          commands will be explained in later chapters.
  21. ;          will be explained in later chapters.
  22. ;
  23. .model SMALL                    ; This defines memory model
  24.         IF1                     ; On first pass
  25.         include maclib.inc      ;   open macro library
  26.         ENDIF                   ; End of macro including block
  27. ;
  28. ;═══════════════  C O D E   S E G M E N T   ═══════════════
  29. ;
  30. .code
  31.  
  32. Begin:                          ;
  33. Next:                           ;
  34.                                 ;
  35.         InpInt  cx              ; Input the number to compute
  36.                                 ;
  37.         cmp     dl,0Dh          ; Check the ENTER key
  38.         je      ExCycle           ; Exit if pressed
  39.         cmp     dl,1Bh          ; Check the ESC key
  40.         je      ExCycle           ; Exit if pressed
  41.                                 ;
  42.         mov     ax,1            ; The initial value of factorial
  43.         cmp     cx,1            ; Check the input value
  44.         jl      Prtres          ; Skip the calculating if the
  45.                                 ;   number is less than 1
  46.         mov     bx,0            ; Clear the work register
  47.                                 ;
  48. Mult:                           ;
  49.         mov     dx,0            ; Clear the high part of result
  50.         inc     bx              ; Increase the work register
  51.         mul     bx              ; The next result
  52.         loop    Mult            ; Continue the cycle
  53.                                 ;
  54. PrtRes:                         ;
  55.                                 ;
  56.         OutInt  ax              ; Put result on screen
  57.                                 ;
  58.         NewLine                 ; Move cursor to the next line
  59.                                 ;
  60.         jmp     Next            ; Proceed next number
  61.                                 ;
  62. ExCycle:                          ;= This label marks end of program
  63.                                 ;
  64.         mov     ax,4C00h        ; AH register contains 4Ch code that is a
  65.                                 ;     DOS function number, AL register
  66.                                 ;     contains return code 00.
  67.         int     21h             ; Dos service "Terminate program"
  68.                                 ;
  69. .stack                          ; This line defines the STACK segment
  70.         end     Begin
  71.  
  72.            This  is  a  sample of an assembler program which
  73.            calculates the function called  n-factorial.   It
  74.            shows commands for organizing cycles and for data
  75.            examination.  To run the program enter the number
  76.            after  the  cursor  and then the separator symbol
  77.            (for example the factorial symbol "!").  To  exit
  78.            the program press the ENTER or ESC key instead of
  79.            the number.  You may meet commands  that  you  do
  80.            not   fully   uderstand   even   if  you  are  an
  81.            experienced user.  Don't worry about  them.   All
  82.            commands will be explained in later chapters.
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.